/*----------------------------------------
	1.2.4) 核心设置
	----------------------------------------*/
	var Admin;
	if (!Admin) Admin = {};
	Admin.cs = {};
	
	/**
	 * main gui of core setting
	 */
	Admin.cs.main = function()
	{
		$(".content_block").spin();
		$.ajax({
			url: cs_path + "core_setting_form",
			success: function(html) {
				$(".content_block").spin(false);
				$(".content_block").html(html);
			}
		});
	}
	
	/**
	 * submit modify of admin folder
	 * @param admin_folder_to_change
	 */
	Admin.cs.submit_admin_folder = function(admin_folder_to_change)
	{
		$(".content_block").spin();
		$.ajax({
			url: cs_path + "admin_folder_submit",
			dataType: 'json',
			data: {admin_folder_to_change: admin_folder_to_change},
			success: function(data) {
				$(".content_block").spin(false);
				$(".message").remove();
				if (data == 'save_succeeded') {
					$("caption").append(
						"<div class='message success'>" +
		                "<p><strong> 管理员文件夹设置 </strong>保存成功<br /><strong> 页面即将跳转到登陆前界面，请您重新登录...</strong></p>" +
		                "</div>"
					);
				} else if (data == 'save_failed') {
					$("caption").append(
						"<div class='message error'>" +
		                "<p><strong> 管理员文件夹设置 </strong>保存失败</p>" +
		                "</div>"
					);
				}
			}
		});
	}
	
	/**
	 * submit modify of other core setting
	 * @param core_setting_array
	 */
	Admin.cs.submit_core_setting = function(core_setting_array)
	{
		$(".content_block").spin();
		$.ajax({
			url: cs_path + "core_setting_submit",
			dataType: 'json',
			data: {core_setting_array: core_setting_array},
			success: function(data) {
				$(".content_block").spin(false);
				$(".message").remove();
				if (data == 'save_succeeded') {
					$("caption").append(
						"<div class='message success'>" +
		                "<p><strong> 核心设置 </strong>保存成功</p>" +
		                "</div>"
					);
				} else if (data == 'save_failed') {
					$("caption").append(
						"<div class='message error'>" +
		                "<p><strong> 核心设置 </strong>保存失败</p>" +
		                "</div>"
					);
				}
			}
		});
	}
	
	// listen to 'submit admin folder' button
	$(".cs#submit_admin_folder").live('click', function() {
		admin_folder_to_change = $(this).prev().val();
		if (admin_folder_to_change == "") {
			alert("文件夹名称不应为空");
			$(this).prev().val(admin_folder);
			return;
		}
		if (admin_folder_to_change == admin_folder) {
			alert("请先修改文件夹名称");
			return;
		}
		if (confirm('确定要修改' + $(this).parent().prev().html() + '为 "' + admin_folder_to_change + '" ?')) {
			Admin.cs.submit_admin_folder(admin_folder_to_change);
			setTimeout("$('.message').slideUp(200)", 3000);
			setTimeout("location.replace(base_url + 'index.php/' + admin_folder_to_change + '/login');", 2000);
		} else {
			$(this).prev().val(admin_folder);
			return false;
		}
	});
	
	// listen to 'submit other core setting' button
	$(".cs#submit_other").live('click', function() {
		var is_empty = 0;
		$(":text").each(function() {
			if ($(this).attr("id") != 0 && $(this).val() == '') {
				alert("请填写'" + $(this).parent().prev().html() + "'");
				is_empty = 1;
				return false;
			}
		});
		
		if (is_empty == 1) { return; }
		
		var core_setting_array = new Array();
		$(":text").each(function() {
			if ($(this).attr("id") != 0) {
				core_setting_array[$(this).attr("id")] = $(this).val();
			}
		});
		
		Admin.cs.submit_core_setting(core_setting_array);
		setTimeout("$('.message').slideUp(200)", 3000);
	});
	
	